/*
	libsimple_graphical - unambitious C++ graphical library
	https://notabug.org/namark/libsimple_graphical
	https://gitlab.com/namark/libsimple_graphical
	https://github.com/namark/libsimple_graphical

	Copyright (C) 2017-2019 respective authors/contributors

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "software_window.h"

using namespace simple::graphical;

software_window::software_window(std::string title, int2 size, flags options, int2 position)
	: window(title, size, options, position),
	_surface(SDL_GetWindowSurface(guts().get()))
{}

const surface & software_window::surface() const noexcept
{
	return _surface;
}

void software_window::update_surface()
{
	_surface = free_surface(SDL_GetWindowSurface(guts().get()));
}

const surface & software_window::get_surface()
{
	update_surface();
	return surface();
}

void software_window::update() const
{
	sdlcore::utils::throw_error(SDL_UpdateWindowSurface(guts().get()));
}

bool software_window::refresh() const noexcept
{
	return !sdlcore::utils::check_error(SDL_UpdateWindowSurface(guts().get()));
}

software_window::free_surface::free_surface(SDL_Surface * guts)
	: surface(guts, support::nop)
{}
